package com.qianying.controller.admin;

import com.qianying.comment.CommonResult;
import com.qianying.entity.SysPermission;
import com.qianying.service.SysPermissionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 权限控制器（驼峰命名规范）
 */
@RestController
@RequestMapping("/admin/sysPermission") // 接口路径驼峰（sysPermission）
@Tag(name = "权限管理", description = "权限管理控制器")
public class SysPermissionController {

    @Autowired
    private SysPermissionService sysPermissionService;

    /**
     * 按类名分组查询所有权限（驼峰接口名）
     */
    @GetMapping("/groupByClassName") // 接口路径驼峰（groupByClassName）
    @Operation(
            summary = "获取所有接口，根据功能分组",
            description = "获取所有接口，根据功能分组"
    )
    public CommonResult<?> getAllGroupByClassName( @RequestParam(required = false) Long roleId) {
        return sysPermissionService.getAllGroupByClassName(roleId);
    }

    /**
     * 根据类名和方法名查询（驼峰参数）
     */
    @GetMapping("/queryByClassAndMethod") // 接口路径驼峰
    @Operation(
            summary = "根据类名和方法名获取权限控制器",
            description = "根据类名和方法名获取权限控制器",
            parameters = {
                    @Parameter(name = "className", description = "类名称", example = "SysPermissionController"),
                    @Parameter(name = "methodName", description = "方法名称", example = "getByClassNameAndMethodName"),
            })
    public CommonResult<?>  getByClassNameAndMethodName(
            @RequestParam String className, // 驼峰参数名（与实体类一致）
            @RequestParam String methodName) { // 驼峰参数名
       return sysPermissionService.getByClassNameAndMethodName(className, methodName);
    }

    /**
     * 根据ID查询（驼峰接口）
     */
    @GetMapping("/getById/{id}") // 接口路径驼峰
    @Operation(
            summary = "根据类Id获取权限控制器",
            description = "根据类Id获取权限控制器",
            parameters = {
                    @Parameter(name = "id", description = "控制器Id", example = "id")
            })
    public  CommonResult<?> getById(@PathVariable Long id) {
       return sysPermissionService.getById(id);
    }

    /**
     * 保存或更新权限（驼峰接口）
     */
    @PostMapping("/saveOrUpdate") // 接口路径驼峰
    @Operation(
            summary = "保存或更新",
            description = "保存或更新接口信息",
            parameters = {
                    @Parameter(name = "Id", description = "主键ID", example = "1"),
                    @Parameter(name = "name", description = "控制器名称", example = "10"),
                    @Parameter(name = "className", description = "类名"),
                    @Parameter(name = "requestMapping", description = "接口的请求路径"),
                    @Parameter(name = "description", description = "接口描述"),
                    @Parameter(name = "parentId", description = "父权限ID，一般就是控制器类保存的Id")
            }
    )
    public  CommonResult<?> saveOrUpdate(@RequestBody SysPermission permission) {
       return sysPermissionService.saveOrUpdatePermission(permission);
    }
}